package com.skill.shareskill.utils;

import com.loopj.android.http.AsyncHttpClient;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;


/**
 * Created by Administrator on 2018/1/29 0029.
 */

public class HttpUtils {
    public static final String BASE_PATH = "http://192.168.191.1:8080/mvn-ssm-shareskill/";
    public static String str = null;
    public static String getContent(String serverPath) throws IOException {
        StringBuilder sb = null;
        //连接网络
        //创建一个URL对象
        URL url = new URL(serverPath);
        //与服务器建立连接
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        //设置连接超时时间
        conn.setConnectTimeout(5000);
        //设置读取超时时间
        conn.setReadTimeout(5000);
        //获得一个输入流
        InputStream is = conn.getInputStream();
        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        String temp = null;
        sb = new StringBuilder();
        while ((temp = br.readLine()) != null) {
            sb.append(temp);
        }

        br.close();
        conn.disconnect();
        return sb.toString();
    }
}
